]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensions-tool: Add 'prefs' command
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 11 Jan 2019 11:03:17 +0000 (12:03 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Wed, 21 Aug 2019 16:28:02 +0000 (18:28 +0200)
Easily launching an extension's preference dialog from the command
line can be quicker than using a UI like Tweaks or the extension
website, so add that functionality.

https://gitlab.gnome.org/fmuellner/gnome-extensions-tool/merge_requests/2
https://gitlab.gnome.org/GNOME/gnome-shell/issues/1234

src/extensions-tool/command-prefs.c [new file with mode: 0644]
src/extensions-tool/commands.h
src/extensions-tool/completion/bash/gnome-extensions
src/extensions-tool/main.c
src/extensions-tool/man/gnome-extensions.txt
src/extensions-tool/meson-src.build
src/extensions-tool/meson.build

diff --git a/src/extensions-tool/command-prefs.c b/src/extensions-tool/command-prefs.c
new file mode 100644 (file)
index 0000000..022ff8f
--- /dev/null
@@ -0,0 +1,117 @@
+/* commands-prefs.c
+ *
+ * Copyright 2019 Florian Müllner <fmuellner@gnome.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "commands.h"
+#include "common.h"
+#include "config.h"
+
+static gboolean
+launch_extension_prefs (const char *uuid)
+{
+  g_autoptr (GDBusProxy) proxy = NULL;
+  g_autoptr (GVariant) response = NULL;
+  g_autoptr (GVariant) asv = NULL;
+  g_autoptr (GVariantDict) info = NULL;
+  g_autoptr (GError) error = NULL;
+  gboolean has_prefs;
+
+  proxy = get_shell_proxy (&error);
+  if (proxy == NULL)
+    return FALSE;
+
+  response = g_dbus_proxy_call_sync (proxy,
+                                     "GetExtensionInfo",
+                                     g_variant_new ("(s)", uuid),
+                                     0,
+                                     -1,
+                                     NULL,
+                                     &error);
+  if (response == NULL)
+    return FALSE;
+
+  asv = g_variant_get_child_value (response, 0);
+  info = g_variant_dict_new (asv);
+
+  if (!g_variant_dict_contains (info, "uuid"))
+    return FALSE;
+
+  g_variant_dict_lookup (info, "hasPrefs", "b", &has_prefs);
+  if (!has_prefs)
+    return FALSE;
+
+  g_dbus_proxy_call_sync (proxy,
+                          "LaunchExtensionPrefs",
+                          g_variant_new ("(s)", uuid),
+                          0,
+                          -1,
+                          NULL,
+                          &error);
+
+  return TRUE;
+}
+
+int
+handle_prefs (int argc, char *argv[], gboolean do_help)
+{
+  g_autoptr (GOptionContext) context = NULL;
+  g_autoptr (GError) error = NULL;
+  g_auto(GStrv) uuids = NULL;
+  GOptionEntry entries[] = {
+    { .long_name = G_OPTION_REMAINING,
+      .arg_description = "UUID",
+      .arg = G_OPTION_ARG_STRING_ARRAY, .arg_data = &uuids },
+    { NULL }
+  };
+
+  g_set_prgname ("gnome-extensions prefs");
+
+  context = g_option_context_new (NULL);
+  g_option_context_set_help_enabled (context, FALSE);
+  g_option_context_set_summary (context, _("Opens extension preferences"));
+  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+
+  if (do_help)
+    {
+      show_help (context, NULL);
+      return 0;
+    }
+
+  if (!g_option_context_parse (context, &argc, &argv, &error))
+    {
+      show_help (context, error->message);
+      return 1;
+    }
+
+  if (uuids == NULL)
+    {
+      show_help (context, _("No UUID given"));
+      return 1;
+    }
+  else if (g_strv_length (uuids) > 1)
+    {
+      show_help (context, _("More than one UUID given"));
+      return 1;
+    }
+
+  return launch_extension_prefs (*uuids) ? 0 : 2;
+}
index 247a14434cc00869d054a405287ba5d989d338e9..04de71c7c1776fc8d5ecc6c84d1550dc97815947 100644 (file)
@@ -28,6 +28,7 @@ int handle_enable     (int argc, char *argv[], gboolean do_help);
 int handle_disable    (int argc, char *argv[], gboolean do_help);
 int handle_list       (int argc, char *argv[], gboolean do_help);
 int handle_info       (int argc, char *argv[], gboolean do_help);
+int handle_prefs      (int argc, char *argv[], gboolean do_help);
 int handle_create     (int argc, char *argv[], gboolean do_help);
 int handle_pack       (int argc, char *argv[], gboolean do_help);
 int handle_install    (int argc, char *argv[], gboolean do_help);
index 73b5942812e9d0618a9fda12ff0ab70af724ade5..aaff309c0805262c0336ce243b85cf086f142228 100644 (file)
@@ -5,7 +5,7 @@
 ################################################################################
 
 __gnome_extensions() {
-  local commands="version enable disable info install show list create pack"
+  local commands="version enable disable info install show list create pack prefs"
   local COMMAND=${COMP_WORDS[1]}
 
   _init_completion -s || return
@@ -29,7 +29,10 @@ __gnome_extensions() {
         enable)
           local list_opt=--disabled
           ;;&
-        enable|disable|info|show)
+        prefs)
+          local list_opt=--prefs
+          ;;&
+        enable|disable|info|show|prefs)
           COMPREPLY=($(compgen -W "`gnome-extensions list $list_opt`" -- "$2"))
           return 0
           ;;
index 467f4980506b4bc1e5188f3ebfc73d3b39cc4c16..ef94abc5f7c3975d6c7ae32c58e016837596cab4 100644 (file)
@@ -186,6 +186,7 @@ usage (void)
   g_printerr ("  list      %s\n", _("List extensions"));
   g_printerr ("  info      %s\n", _("Show extension info"));
   g_printerr ("  show      %s\n", _("Show extension info"));
+  g_printerr ("  prefs     %s\n", _("Open extension preferences"));
   g_printerr ("  create    %s\n", _("Create extension"));
   g_printerr ("  pack      %s\n", _("Package extension"));
   g_printerr ("  install   %s\n", _("Install extension bundle"));
@@ -252,6 +253,8 @@ main (int argc, char *argv[])
     return handle_info (argc, argv, do_help);
   else if (g_str_equal (command, "show"))
     return handle_info (argc, argv, do_help);
+  else if (g_str_equal (command, "prefs"))
+    return handle_prefs (argc, argv, do_help);
   else if (g_str_equal (command, "create"))
     return handle_create (argc, argv, do_help);
   else if (g_str_equal (command, "pack"))
index e782103fd61e0fc052f25945111246b908fe80fc..2322f6d31244eb5ed35f21c43385d763c2bbc7ab 100644 (file)
@@ -25,6 +25,8 @@ SYNOPSIS
 
 *gnome-extensions* list ['OPTION'...]
 
+*gnome-extensions* prefs 'UUID'
+
 *gnome-extensions* create ['OPTION'...]
 
 *gnome-extensions* pack ['OPTION'...]
@@ -88,6 +90,10 @@ Displays a list of installed extensions.
   *--details*;;
     Show some extra information for each extension
 
+*prefs* 'UUID'::
+Open the preference dialog of the extension identified by 'UUID'.
+
+
 *create* ['OPTION'...]::
 Creates a new extension from a template.
 +
index 7af5365e4ea8224bf76d91e3b934a7dde80a6e3b..10ca7b42af3887c166b32a15f50a3059717bcf8b 100644 (file)
@@ -7,6 +7,7 @@ sources = [
   'command-install.c',
   'command-list.c',
   'command-pack.c',
+  'command-prefs.c',
   'common.h',
   'main.c'
 ]
index 39022749013bd447896ac6474ec5719fbfdf9268..ab93e85c8fd46ba6d26dbc906c58cf70e27d401c 100644 (file)
@@ -16,6 +16,7 @@ sources = [
   'command-install.c',
   'command-list.c',
   'command-pack.c',
+  'command-prefs.c',
   'main.c'
 ]